using System;

namespace PCSharp.DemoDelegate
{
    public delegate double Rebate(double val);
    public delegate bool Call();

    public class ElectronicStore
    {
        private string itemName;
        private float rate;
        private double itemPrice;
        private int quantity;

        public string ItemName
        {
            get { return itemName; }
            set { itemName = value; }
        }

        public float Rate
        {
            get { return rate; }
            set { rate = value; }
        }

        public double ItemPrice
        {
            get { return itemPrice; }
            set { itemPrice = value; }
        }

        public int Quantity
        {
            get { return quantity; }
            set { quantity = value; }
        }

        public bool ChooseProduct()
        {
            Console.WriteLine("Select the product sold");
            Console.WriteLine(" 1. Air Conditioner\n 2. Television\n 3. Washing Machine");

            int choice = 0;
            do
            {
                Console.Write("Enter your choice: ");
                choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                    case 1:
                        ItemName = "Air Conditioner";
                        break;
                    case 2:
                        ItemName = "Television";
                        break;
                    case 3:
                        ItemName = "Washing Machine";
                        break;
                    default:
                        Console.WriteLine("Invalid choice");
                        break;
                }
            } while (choice < 1 || choice > 3);

            AcceptDetails();
            return true;
        }

        public void AcceptDetails()
        {
            bool valid;
            do
            {
                valid = true;

                Console.Write("Enter the product price: ");

                try
                {
                    itemPrice = Convert.ToDouble(Console.ReadLine());

                    if (itemPrice < 0)
                    {
                        Console.WriteLine("Value of product cannot be negative");
                        valid = false;
                    }
                }
                catch (FormatException objFormatOne)
                {
                    Console.WriteLine("Error: " + objFormatOne.Message);
                    valid = false;
                }
            } while (!valid);

            do
            {
                Console.Write("Enter the quantity sold: ");

                valid = Int32.TryParse(Console.ReadLine(), out quantity);

                if (!valid)
                {
                    Console.WriteLine("Error: FormatException");
                }
                else if (quantity < 0)
                {
                    Console.WriteLine("Quanity cannot be negative");
                    valid = false;
                }
            } while (!valid);
        }

        public double Discount(double val)
        {
            double discount;

            if (val <= 1000)
            {
                discount = val * 0.1;
                Rate = 10;
            }
            else if ((val > 1000) && (val <= 2000))
            {
                discount = val * 0.2;
                Rate = 20;
            }
            else if ((val > 2000) && (val <= 3000))
            {
                discount = val * 0.3;
                Rate = 30;
            }
            else
            {
                discount = val * 0.5;
                Rate = 50;
            }

            return discount;
        }

        public double ValueOfGoods()
        {
            double value = quantity * itemPrice;
            return value;
        }
    }
}